<!-- categories block -->

{assign var='types' value=','|explode:$types}

{if !$block.Tpl}
	<div class="caption" style="padding-bottom: 0;">
		<b>
		{if $types|@count > 1}
			{$lang.categories}
		{else}
			{$listing_types[$types.0].name}
		{/if}
		</b>
	</div>
{else}
	<div style="padding-top: 5px"></div>
{/if}

{foreach from=$types item='type'}
	{if $types|@count > 1}
		{include file='blocks'|cat:$smarty.const.RL_DS|cat:'fieldset_header.tpl' name=$listing_types.$type.name id='addcatblock'|cat:$listing_types.$type.Key class='categories_padding'}
	{/if}
	
	{assign var='listing_type' value=$listing_types.$type}
	
	{if $categories.$type}
		{math assign='pages_number' equation='ceil(count/num)' count=$categories.$type|@count num=$listing_type.Ablock_visible_number}
		<div class="categories" id="categories_{$type|replace:'_':''}_{$pages_number}">
			<ul>
				<li>
				<table class="fixed">
				<tr>
				{foreach from=$categories.$type item='cat' name='fCats'}
					<td valign="top">
						<div class="item">
							{rlHook name='tplPreCategory'}
							<a class="category" title="{$cat.name}" href="{$rlBase}{if $config.mod_rewrite}{$pages[$listing_type.Page_key]}/{$cat.Path}{if $listing_type.Cat_postfix}.html{else}/{/if}{else}?page={$pages[$listing_type.Page_key]}&amp;category={$cat.ID}{/if}">{$cat.name}</a>
							{if $listing_type.Cat_listing_counter}
								<span>(<b>{$cat.Count}</b>)</span>
							{/if}
							{rlHook name='tplPostCategory'}
							
							{if !empty($cat.sub_categories) && $listing_type.Ablock_show_subcats}
							<div class="sub_categories">
								{if $listing_type.Ablock_subcat_number}
									{section loop=$cat.sub_categories name='sub_cat' max=$listing_type.Ablock_subcat_number}
										{rlHook name='tplPreSubCategory'}
										<a title="{$cat.sub_categories[sub_cat].name}" href="{$rlBase}{if $config.mod_rewrite}{$pages[$listing_type.Page_key]}/{$cat.sub_categories[sub_cat].Path}{if $listing_type.Cat_postfix}.html{else}/{/if}{else}?page={$pages[$listing_type.Page_key]}&amp;category={$cat.sub_categories[sub_cat].ID}{/if}">{$cat.sub_categories[sub_cat].name}</a>{if $smarty.section.sub_cat.last}{if $cat.sub_categories|@count > $listing_type.Ablock_subcat_number}<span class="more" title="{$lang.show_other_categories}">&nbsp;&raquo;</span>{/if}{else}, {/if}
									{/section}
									
									<div class="hide other_categories">
										{section loop=$cat.sub_categories name='sub_cat' start=$listing_type.Ablock_subcat_number}
											{rlHook name='tplPreSubCategory'}
											<a title="{$cat.sub_categories[sub_cat].name}" href="{$rlBase}{if $config.mod_rewrite}{$pages[$listing_type.Page_key]}/{$cat.sub_categories[sub_cat].Path}{if $listing_type.Cat_postfix}.html{else}/{/if}{else}?page={$pages[$listing_type.Page_key]}&amp;category={$cat.sub_categories[sub_cat].ID}{/if}">{$cat.sub_categories[sub_cat].name}</a>{if !$smarty.section.sub_cat.last}, {/if}
										{/section}
									</div>
								{else}
									{foreach from=$cat.sub_categories item='sub_cat' name='subCatF'}
										{rlHook name='tplPreSubCategory'}
										<a title="{$sub_cat.name}" href="{$rlBase}{if $config.mod_rewrite}{$pages[$listing_type.Page_key]}/{$sub_cat.Path}{if $listing_type.Cat_postfix}.html{else}/{/if}{else}?page={$pages[$listing_type.Page_key]}&amp;category={$sub_cat.ID}{/if}">{$sub_cat.name}</a>{if !$smarty.foreach.subCatF.last}, {/if}
									{/foreach}
								{/if}
							</div>
							{/if}
						</div>
					</td>
					
					{if $smarty.foreach.fCats.iteration%$listing_type.Ablock_columns_number == 0 && ($smarty.foreach.fCats.iteration%$listing_type.Ablock_visible_number != 0 || !$listing_type.Ablock_visible_number) && !$smarty.foreach.fCats.last}
					</tr>
					<tr>
					{/if}
					
					{if $smarty.foreach.fCats.iteration%$listing_type.Ablock_visible_number == 0 && $listing_type.Ablock_visible_number && !$smarty.foreach.fCats.last}
					</tr>
					</table>
					{if $listing_type.Ablock_visible_number}
					</li><li class="hide">
					{/if}
					<table class="sTable" style="table-layout: fixed;">
					<tr>
					{/if}
				{/foreach}
				{if $smarty.foreach.fCats.total%$listing_type.Ablock_columns_number != 0}
					{math assign='rest' equation='(ceil(total/cols)*cols) - total' total=$smarty.foreach.fCats.total cols=$listing_type.Ablock_columns_number}
					{section name='rest' loop=$rest|ceil}
						<td></td>
					{/section}			
				{/if}
				</tr>
				</table>
				</li>
			</ul>
			<div class="clear"></div>
		</div>
		
		{if $smarty.foreach.fCats.total > $listing_type.Ablock_visible_number && $listing_type.Ablock_visible_number}
			{assign var='pages_number' value=$smarty.foreach.fCats.total/$listing_type.Ablock_visible_number}
			<div class="slider_bar{if $types|@count > 1} slider_bar_light{/if}">
				<div class="prev hide" title="{$lang.show_previous_categories}"></div>
				<div class="navigation">
					{section name='slide_page' loop=$pages_number|ceil}
						<a title="{$lang.show_other_categories}" accesskey="{$smarty.section.slide_page.iteration}" {if $smarty.section.slide_page.first}class="active"{/if} href="javascript:void(0)"><span>&nbsp;</span></a>
					{/section}
				</div>
				<div class="next" title="{$lang.show_next_categories}"></div>
			</div>
			
			<script type="text/javascript">
			var catSlider = false;
			{literal}
			$(document).ready(function(){
				if ( !catSlider )
				{
					$('div.categories').flCatSlider();
				flynax.moreCategories();
					catSlider = true;
				}
			});
			{/literal}
			</script>
		{/if}
	
	{else}
		<div style="padding: 10px 12px;">{$lang.listing_type_no_categories}</div>
	{/if}
	
	{if $types|@count > 1}
		{include file='blocks'|cat:$smarty.const.RL_DS|cat:'fieldset_footer.tpl'}
	{/if}
	
{/foreach}

<!-- categories block end -->